﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;
using Entity;
using System.Text;
public partial class admin_Index : PageBase
{
    string LoginUser = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["LoginUser"] == null)
        {
            return;
        }
        if (!IsPostBack)
        {
            LoginSessionEntity loginSession = (LoginSessionEntity)Session["LoginUser"];
            LoginUser = loginSession.LoginName;
            lblName.Text = loginSession.UserName;
            lblEmail.Text = loginSession.Email;
        }
        LoadMenu();
    }

    /// <summary>
    /// 加载菜单
    /// </summary>
    private void LoadMenu()
    {



        List<SysFun> sysFunction = SysFunDAL.Instance.SelectSysFunction(LoginUser);
        List<SysFun> sysFunctionNew = new List<SysFun>();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < sysFunction.Count; i++)
        {
            if (sysFunction[i].Is_dir == "1")
            {
                sysFunctionNew.Add(sysFunction[i]);
            }
        }

        for (int i = 0; i < sysFunctionNew.Count; i++)
        {
            sb.Append("<li>");
            sb.Append("<h2>"+sysFunctionNew[i].Name+"</h2>");
            sb.Append("<div>");

            for (int j = 0; j < sysFunction.Count; j++)
            {
                if (sysFunction[j].Parent_id == sysFunctionNew[i].ID && sysFunction[j].Is_dir == "0")
                {
                    if (sysFunction[j].Name.IndexOf("网站基本信息设置") != -1)
                    {
                        sb.Append("<a href=\"" + sysFunction[j].Url + "\" class=\"currleft\" target=\"mainFrame\">");
                    }
                    else
                    {
                        sb.Append("<a href=\"" + sysFunction[j].Url + "\" target=\"mainFrame\">");
                    }
                    sb.Append("<img src=\"img/icons/"+sysFunction[j].Logo+"\" alt=\"\">");
                    sb.Append(sysFunction[j].Name);
                    sb.Append("</a>");
                }
            }
            sb.Append("</div>");
            sb.Append("</li>");
        }

        ligMenu.Text = sb.ToString();
    }

    /// <summary>
    /// 退出
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        Session["LoginUser"] = null;
        Response.Write(" <script> top.location.href= 'login.aspx'; </script> ");
    }
}